Skip to content

Return ErrBusyBuffer instead of driver.ErrBadConn #611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Return ErrBusyBuffer instead of driver.ErrBadConn #611

wants to merge 1 commit into from

Conversation

amenzhinsky
Copy link

@amenzhinsky amenzhinsky commented Jun 8, 2017

#314

We ran into problem when using the same tx and querying multiple times, the mysql driver returns driver.ErrBadConn sending the busy buffer error to stderr. I believe that in most cases buffer cannot be taken only when previous one hasn't been read out or closed.

See TestUnclosedRows as an example in the changes.

This is more like error message improvement since current behaviour is quite confusing.

@julienschmidt
Copy link
Member

Interesting, we were always looking for a way to reproduce those errors.

In that case, we should probably return a more descriptive error like e.g. ErrUnreadData or more specific ErrUnreadTxRows. ErrBusyBuffer was just the best name we could come up for an error we couldn't find any explanation for.

@julienschmidt julienschmidt added this to the v1.4 milestone Jun 8, 2017
@julienschmidt
Copy link
Member

And please don't ignore our pull request template, specifically Added myself / the copyright holder to the AUTHORS file in the checklist 😉

if b.length > 0 {
return nil
return nil, ErrUnreadTxRows
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not return the error here. Leave the buffer unchanged.
This specific error should only be returned when we know that it is this specific error.

return driver.ErrBadConn
data, err := mc.buf.takeSmallBuffer(pktLen + 4)
if err != nil {
return err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example here it should be impossible that we're in a transaction with unread rows. Here the driver.ErrBadConn should still be returned as there is this is a brand new connection and there really shouldn't be any unread data in the buffer.

Copy link
Author

@amenzhinsky amenzhinsky Jun 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had some time to sort things out, I think that's correct behaviour to return ErrBusyBuffer because when we cannot take it then something must be wrong in the code (multiple functions are using the buffer at the same time) or in this case buffer has some unread data.

And only two functions writePacket and readPacket should return ErrBadConn since they do the io.

So we should return ErrBusyBuffer anyway not ErrBadConn, and probably add additional checks to Query and Exec to return ErrUnreadRows to be more descriptive.

What do you think?

@julienschmidt
Copy link
Member

@amenzhinsky do you still have problems with the now implemented behavior (see #302)?
If yes, please update this PR or otherwise close it.

@julienschmidt julienschmidt modified the milestones: v1.4.0, v1.5.0 May 15, 2018
@methane
Copy link
Member

methane commented Oct 21, 2018

Close this because no reply.

@methane methane closed this Oct 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants